package cn.hnbjx.prepaid.controller;

import cn.hnbjx.prepaid.pojo.News;
import cn.hnbjx.prepaid.service.NewsService;
import cn.hnbjx.prepaid.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/admin")
public class NewsController {
    @Autowired
    private NewsService newsService;

    @GetMapping("/news/list")
    public Result list(int page,String key) {
        return Result.ok(newsService.allNews(page,key));
    }
    @GetMapping("/news/delete")
    public Result delete(Integer id){
        newsService.delete(id );
        return Result.ok("删除成功");
    }
    @GetMapping("/news/get")
    public Result get(Integer id){
        return Result.ok(newsService.findNews(id ));
    }
    @PostMapping("/news/add")
    public Result add(News news){
        newsService.insertNews(news);
        return Result.ok("添加成功");
    }
    @PostMapping("/news/update")
    public Result update(News news){
        newsService.updateNews(news);
        return Result.ok("更新成功");
    }
}
